package com.fate.framework.handler;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import java.time.LocalDateTime;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CraneMetaObjectHandler implements MetaObjectHandler {
  @Override
  public void insertFill(MetaObject metaObject) {
    this.setFieldValByName("gmtCreate", LocalDateTime.now(), metaObject);
    this.setFieldValByName("gmtModified", LocalDateTime.now(), metaObject);
    try {
      this.setFieldValByName("creatorId", StpUtil.getLoginId(), metaObject);
    } catch (Exception e) {
      log.error("插入creatorId失败{}", e.getMessage());
    }
  }

  @Override
  public void updateFill(MetaObject metaObject) {
    this.setFieldValByName("gmtModified", LocalDateTime.now(), metaObject);
  }
}
